<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>大图管理</title>
<%@include file="../../head.jsp"%>

</head>
<body>
	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="imageType" formatter="formatCell">大图类型</th>
				<th field="imageTitle">标题</th>
				<th field="imageDesc">简介</th>
				<th field="linkUrl">链接地址</th>
				<th field="origImage" formatter="renderImg">大图地址</th>

			</tr>
		</thead>
	</table>
	<script type="text/javascript">
		var imageType = {
			"1" : "首页",
			"2" : "风格偏好",
			"3" : "酒店"

		};
		function formatCell(value, row, index) {
			return imageType[value];
		}
		function renderImg(value, row, index) {
			return "<img src='${image_domain}"+value+"' width='150' height='100'>";
		}
	</script>

	<div id="addBigImageDialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true">
	</div>

	<script type="text/javascript">
		$('#list_data')
				.datagrid(
						{
							title : '大图信息',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 500,
							doSize : true,
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : false,
							url : '${cpath }/admin/bigimage/list',
							//sortName: 'code', 
							//sortOrder: 'desc', 
							remoteSort : false,
							idField : 'imageId',
							singleSelect : true,//是否单选 
							pagination : false,//分页控件 
							rownumbers : true,//行号 
							//frozenColumns:[[ 
							//    {field:'ck',checkbox:true} 
							//]], 
							toolbar : [
									{
										text : '添加首页或酒店首页大图',
										iconCls : 'icon-add',
										handler : function() {
											var saveAction = cpath
													+ '/admin/bigimage/save';
											var openAction = cpath
													+ '/admin/bigimage/vsave';
											openAddDestinationDialog(
													'添加首页或酒店首页大图', openAction,
													saveAction,
													addBigImgSuccess);
										}
									},
									'-',
									{
										text : '修改首页或酒店首页大图',
										iconCls : 'icon-add',
										handler : function() {
											var saveAction = cpath
													+ '/admin/bigimage/update';
											var openAction = cpath
													+ '/admin/bigimage/vupdate';
											openUpdateDestinationDialog('修改首页或酒店首页大图',
													openAction, saveAction,
													addBigImgSuccess,getSelectBigInfo);
										}
									},
									'-',
									{
										text : '删除选中大图',
										iconCls : 'icon-remove',
										handler : function() {
											var deleteAction = cpath
													+ '/admin/bigimage/delete';
											// var openAction =  cpath +'/admin/bigimage/bigimage.do?action=toAddActivityAndHotelImages';
											deleteImg(deleteAction,
													addBigImgSuccess);
										}
									}, '-', {
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									} ]
						});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';
		function addBigImgSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}

		function openAddDestinationDialog(dlgtitle, openAction, saveAction,
				successCallback) {

			$('#addBigImageDialog').dialog({
				title : dlgtitle,
				width : 600,
				height : 400,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-save",
					handler : function() {
						saveForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addBigImageDialog').dialog('close');
					}
				} ]
			});
			$('#addBigImageDialog').dialog('open');
		}
		function getSelectBigInfo() {
			return $('#list_data').datagrid('getSelected');
		}
		function openUpdateDestinationDialog(dlgtitle, openAction, saveAction,
				successCallback,getSelectBigInfo) {
			
			//添加信息，需要是否有前置条件
			if (getSelectBigInfo) {
				var row = getSelectBigInfo();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要修改的大图信息！", "info");
					return;
				}
				else
				{
					openAction += '?imageId='+row.imageId;
				}
			}
			
			$('#addBigImageDialog').dialog({
				title : dlgtitle,
				width : 600,
				height : 400,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-save",
					handler : function() {
						saveForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addBigImageDialog').dialog('close');
					}
				} ]
			});
			$('#addBigImageDialog').dialog('open');
		}
		var save_status = false;
		function saveForm(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addBigImageDialog').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}
		function deleteImg(deleteAction, successCallback) {
			var row = $('#list_data').datagrid('getSelected');
			//没有选中行，则需要提示
			if (!row) {
				$.messager.alert("提示", "请选择要删除的大图！", "info");
				return;
			}
			if (row) {
				$.messager.confirm("提示", "确认要删除该大图吗？", function(r) {
					if (r) {
						$.post(deleteAction, row, function(result) {
							if (result.resultCode === '00000000') {
								$('#list_data').datagrid('reload'); // reload the user data
								$.messager
										.alert("提示", result.resultMsg, "info");
								$('#list_data').datagrid('clearSelections');
							} else {
								$.messager.alert("错误", result.resultMsg,
										"error");
								$('#list_data').datagrid('clearSelections');
							}
						}, 'json');
					}
				});
			}
		}
	</script>
	<style type="text/css">
#fm {
	margin: 0;
	padding: 40px 40px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 90px;
}
</style>
</body>
</html>